﻿using MySkin.View;
using Clothing.Base.Framework.Data;
using Clothing.Base.Framework.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using Clothing.Base.Framework.Interface;

namespace Clothing.Option.Login
{
    public partial class LoginForm : BaseForm
    {
        public LoginForm()
        {
            InitializeComponent();
            InitForm();
        }
        new protected void InitForm()
        {
            BtnMax.Hide();
            btnMenu.Hide();
            btnSkin.Hide();
            this.BtnMin.Location = this.BtnMax.Location;
            List<PostionInfo> postionInfoList = DataManger.Instance().GetPostionInfo();
            foreach (var item in postionInfoList)
            {
                this.cobPosition.Items.Add(item);
            }
            
        }

        void setControlShow(string key)
        {
            PostionInfo Position = cobPosition.SelectedItem as PostionInfo;
            string controlDll = "Clothing.Option." + Position.EnglishName + ".dll";
            string controlName = "Clothing.Option." + Position.EnglishName + ".View." + Position.EnglishName + "Control";
            string name = System.Environment.CurrentDirectory;
            Assembly assembly = Assembly.LoadFile(name + "\\" + controlDll);
            IHandlerControlShow controlDisplay = (IHandlerControlShow)assembly.CreateInstance(controlName);
            if (controlDisplay != null)
            {
                Form display = controlDisplay.GetDisplayControl();
                display.Show();
                display.FormClosing += display_FormClosing;
                this.Hide();
            }     
        }

        void display_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Show();
        }

        private void lblLogin_Click(object sender, EventArgs e)
        {
            setControlShow(cobPosition.Text);
        }

    }
}
